﻿using System.Windows;
using System.Windows.Controls;

namespace AlimentadorGenerator
{
    /// <summary>
    /// Interaction logic for GenerateCtrl.xaml
    /// </summary>
    public partial class GenerateCtrl : UserControl
    {
        private RegisterCode m_registerCode;
        private string m_request;
        private string m_response;

        public GenerateCtrl()
        {
            InitializeComponent();
            
            m_registerCode = new RegisterCode();
            m_request = "";
        }

        public RegisterCode GetRegisterCode
        {
            get
            {
                return m_registerCode;
            }
        }

        private void ResponseTxtBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
            ResponseTxtBox.Text = ResponseTxtBox.Text.ToUpper();
        }

        private void RequestTxtBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
            RequestTxtBox.Text = RequestTxtBox.Text.ToUpper();
        }

        private void GenerateBtnClick(object sender, RoutedEventArgs e)
        {
             GenerateValues();
        }

        private void GenerateValues()
        {
            m_registerCode = new RegisterCode();

            if (m_registerCode.RequestCode())
            {
                m_request = m_registerCode.GetRequestCode;
                RequestTxtBox.Text = m_request;

                if (m_registerCode.ResponseCode(m_request))
                {
                    m_response = m_registerCode.GetResponseCode;
                    ResponseTxtBox.Text = m_response;
                }
            }
        }
    }
}
